/*
 * Copyright (c) 2006, 2021, webrx.cn All rights reserved.
 *
 */
package cn;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>Project: mybatis2021 - Demo
 * <p>Powered by webrx On 2021-07-12 10:57:00
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 15
 */
public class Demo {
    public static void main(String[] args) throws IOException {
        //建立SqlSessionFactory
        InputStream is = Resources.getResourceAsStream("mybatis-config.xml");
        SqlSessionFactory sf = new SqlSessionFactoryBuilder().build(is);

        //建立SqlSession
        SqlSession session = sf.openSession();

        //session.getConnection() mybatis SqlSession 提供了一个JDBC接口

        String v = session.selectOne("ver",String.class);
        System.out.println(v);

        List<String> dbs = session.selectList("dbs");
        System.out.println(dbs);


        Map<String,Object> map = new HashMap<String, Object>();
        map.put("username","周三");
        map.put("password","123");
        map.put("qq","7031633");
        map.put("email","7031633@qq.com");
        map.put("phone","33332423");
        int rows = session.insert("save",map);
        System.out.println(rows);
        session.commit();


        List<Map<String,Object>> list = session.selectList("showuser");
        System.out.println(list);
    }
}
